
import BaseModel from "../base/model/BaseModel";
import { LangLabelManager} from "./LangLabelManager";
import { LangButtonManager } from "./LangButtonManager";
import { LangSpriteManager } from "./LangSpriteManager";
import XlsxData from "../config/XlsxData";
import { LangLabel } from "./LangLabel";
import { LangSprite } from "./LangSprite";
import { LangButton } from "./LangButton";
export default class LangManager extends BaseModel{
    private langName:string;
    private labelManager: LangLabelManager;
    private buttonManager: LangButtonManager;
    private spriteManager: LangSpriteManager;
    constructor(){
        super();
        this.labelManager = new LangLabelManager();
        this.spriteManager = new LangSpriteManager();
        this.buttonManager = new LangButtonManager();
    }
    setPath(path:string){
        this.spriteManager.setPath(path);
        this.buttonManager.setPath(path)
    }
    init(label:LangLabelManager,sprite:LangSpriteManager,button:LangButtonManager){
        this.labelManager = label;
        this.spriteManager = sprite;
        this.buttonManager = button;
    }
    getLocalString(key:string,opt?){
        return this.labelManager.getValue(key,opt);
    }

    setLang(langName:string,data:XlsxData){
        this.langName = langName;
       
        this.labelManager.setLang(langName,data);
        this.buttonManager.setLang(langName);
        this.spriteManager.setLang(langName)
    }

    getLang(){
        return this.langName;
    }

    setLocalSprite(node:cc.Node|cc.Component,langID:string){
        if(!node ) {
            cc.log("setLocalSprite sprite is null ");
            return;
        }
        let comp = node.getComponent(LangSprite);
        if(!comp) {
            comp = node.addComponent(LangSprite);
        } else {
        }
        comp.setValue(this.spriteManager,langID);         
    }

    setLocalString(node:cc.Node|cc.Component,langID:string,opt?){
        if(!node ) {
            cc.log("setLocalSprite sprite is null ");
            return;
        }
        let comp = node.getComponent(LangLabel);
        if(!comp) {
            comp = node.addComponent(LangLabel);
        } else {
        }

        comp.setValue(this.labelManager,langID,opt);         
    }

    setLocalButton(node:cc.Node|cc.Component,langID:string,langID2:string = langID){
        if(!node ) {
            cc.log("setLocalSprite sprite is null ");
            return;
        }
        let comp = node.getComponent(LangButton);
        if(!comp) {
            comp = node.addComponent(LangButton);
        } else {
        }
        comp.setValue(this.buttonManager,langID,langID2);         
    }    
}
